<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div   class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'',split:true" style="height:40px;background-color:#e6edfd;">
    	<form action="" id="providerForm"  >
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>中文名称</span></td>
				<td class="screen-n">
					<input type="text" id="buyer_chsName" class="screen-input" style="width:200px" onkeydown="pms.kd13('initBuyers')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initBuyers()">
				</td>
			</tr>
		</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="buyerGrid"></table>
	</div>
</div>  
<script>
var toolbar = [{
	text:'选择',
    iconCls:'ext-icon-note_add',
    handler:function(){
    	var rows = buyersTable.getCheckedData();
		if(rows==null || rows.length==0){
			alertWarning("请选中要添加的客户!");
			return;
		}
		//采购商审核
		if(confirm("确定批量添加?")){
			var buyerCodes = [];
			for(var i=0; i<rows.length; i++){
				buyerCodes.push(rows[i].buyerCode);
			}
			var buyerCodeList = buyerCodes.toString();
			parent.getBuyer(buyerCodeList);
		}
    }
}];
var buyersTable;
$(function(){
	initBuyers();
});
function getParams(){
	var providerCode = "<%=request.getParameter("providerCode")%>";
	var salesmanId = "<%=request.getParameter("salesmanId")%>";
	//console.log(providerCode);
	//console.log(salesmanId);
	var queryParamss ;
	if(providerCode != "null" ){
		queryParamss = {
		    	"providerCode":"<%=request.getParameter("providerCode")%>",
				"chsName":$('#buyer_chsName').val()
		    };
	}
	if(salesmanId != "null"){
		queryParamss = {
		    	"salesmanId":"<%=request.getParameter("salesmanId")%>",
				"chsName":$('#buyer_chsName').val()
		    };
	}
    
	return queryParamss;
}
function initBuyers(){
	buyersTable = $('#buyerGrid').pDataGrid({
		toolbar:toolbar,
		columns:[[  {field:'ck',checkbox:true},
					{field:'chsName',title:'中文名称',align:'center'},
					{field:'buyerCode',title:'采购商编号',align:'center'},
					{field:'spell',title:'拼音码',align:'center'},
					{field:'salesman',title:'销售员',align:'center'},
					{field:'phone',title:'电话',align:'center'},
					{field:'areaName',title:'所属地区',align:'areaName'},
					{field:'address',title:'地址',align:'center'},
					{field:'approvedStatus',title:'是否有效',align:'center',formatter:function(value){
							if(value=="0"){
								return '无效';
							}else{
								return '有效';
							}
					}},
					{field:'isValid',title:'是否审核',align:'center',formatter:function(value){
							if(value=="0"){
								return '未审';
							}else{
								return '审核';
							}
					}}
		          ]],
		          url:'<c:url value="/buyer/getBuyerList.do"/>',  
		    pagination:true,//分页控件
		    pageSize:30,
		    singleSelect:false,
		    rownumbers:true,
		    queryParams:getParams(),
			onDblClickRow:function(index,row){
				parent.getBuyer(row.buyerCode);
			},
			onLoadSuccess : function(data) {
				var panel = $(this).datagrid('getPanel');
				var tr = panel.find('div.datagrid-body tr');
				tr.each(function() {
					var td = $(this).children('td[field="chsName"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
				tr.each(function() {
					var td = $(this).children('td[field="areaName"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
				tr.each(function() {
					var td = $(this).children('td[field="address"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
			}
	}); 
}

 
</script>
